<?php

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$gametype = intval(getvar("gametype"));
$chkGametype = chkGametype($gametype);
if ($gametype == 0)
{
    header("Location:op.php?op=admin&fp=srate1");
    exit();
}
if ($chkGametype == 3)
{
    header("Location:op.php?op=admin&fp=srate_5h&gametype={$gametype}");
    exit();
}
require_once( "class_3d/CheckMode_3d.php" );
$chk = new CheckMode_3d($curruser['acl'], 3, $gametype);
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
$show5N = getShow35($gametype);
$betname_3d = judge_type($gametype);
unset($chk);
$tblName = $g_gametype_3d[$gametype]['ch'];
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
require_once( "class_3d/SRate_3d.php" );
require_once( "class_3d/SRateTbl_3d.php" );
require_once( "class_3d/RateConfig_3d.php" );
if ($show5N)
{
    $SRateTbl_3d = new SRateTbl_5n($gametype);
    $show5NStr = "true";
}
else
{
    $SRateTbl_3d = new SRateTbl_3n($gametype);
    $show5NStr = "false";
}
$SRateTbl_3d->initData($gametype);
$SRate_3d = $SRateTbl_3d;
$RateConfig_3d = new RateConfig_3d($gametype);
$disk = isset($_POST['disk']) || isset($_GET['disk']) ? getvar("disk") : "a";
$playtype = getvar("playtype");
$bid = getvar("bid");
$alertMsg = "";
$alertMsgSyn = "";
$fieldArr = array ("method" => "5", "gametype" => $gametype, "round" => "0", "lotto_id" => "0", "betcontent" => "", "orate" => "", "nrate" => "", "pagename" => "2", "paperopen" => $RateConfig_3d->getPaperOpen());
$disk = $disk == "" ? "a" : $disk;
$playtype = isset($RateConfig_3d->playtypeArr02[$playtype]) ? $playtype : "r1";
$bidstr = "";
if ($bid == "")
{
    $bidstr = "";
}
else
{
    $bid = intval($bid);
    if (!in_array($bid, $RateConfig_3d->playGroupArr02[$playtype]))
    {
        diemsg("{$tblName}玩法资料错误。");
    }
    $bidstr = "&bid=" . $bid;
    $tpl->set("bid", $bid);
}
if (!$RateConfig_3d->checkDiskType($disk))
{
    diemsg("{$tblName}不合法的盘类{$disk}");
}
$diskIdx = $RateConfig_3d->disk_idx[$disk];
if ($bid != "")
{
    $fieldsArr = array ($bid);
}
else
{
    $fieldsArr = $RateConfig_3d->playGroupArr02[$playtype];
}

$msg = "";
if (in_array($playtype, $RateConfig_3d->showAllSubArr02))
{
    $subFlag = 1;
    $subid = intval(getvar("subid"));
    if (in_array($playtype, array ("r2", "r3")))
    {
        $subFlag = 0;
    }
}
else
{
    $subFlag = 0;
    $subid = 0;
}
if (!isset($RateConfig_3d->subArr[$subid]))
{
    diemsg("不合法的类别");
}
$SRateTbl_3d->subid = $subid;
if (ispost())
{
    $tempStr = "";
    $okI = 0;
    $subIdArr = array (0);
    if (isset($_POST['rateSynGametype']))
    {
        if ($chkGametype == 1)
        {
            $synStr = $tblName . "赔率为主, 福体彩赔率同步";
            $synGArr = array (1, 2);
        }
        else if ($show5N)
        {
            $synStr = $tblName . "赔率为主, 五码赔率同步";
            $synGArr = array (11, 12, 13, 14, 15);
        }
        else if (!$g_5number_3d && 2 < $gametype)
        {
            $synStr = $tblName . "赔率为主, 时时彩赔率同步";
            $synGArr = array (10, 11, 12, 13, 14, 15);
        }
        else
        {
            exit("error");
        }
        if ($SRate_3d->updateRateSynGametype($g_5number_3d))
        {
            $fieldArr['betcontent'] = $synStr;
            $fieldArr['orate'] = "0";
            $fieldArr['nrate'] = "0";
            foreach ($synGArr as $val)
            {
                $fieldArr['gametype'] = $val;
                setRateRecord($fieldArr);
            }
            $alertMsgSyn = "alert('{$synStr}');";
        }
        else
        {
            $fieldArr['betcontent'] = $synStr . "失败";
            $fieldArr['orate'] = "0";
            $fieldArr['nrate'] = "0";
            foreach ($synGArr as $val)
            {
                $fieldArr['gametype'] = $val;
                setRateRecord($fieldArr);
            }
            $alertMsgSyn = "alert('{$synStr}');";
        }
    }
    else if ($subFlag && $show5N && isset($_POST['synSub0toSub12']))
    {
        $tempI = 0;
        foreach ($fieldsArr as $val)
        {
            if (in_array($val, $g_n3n5Arr))
            {
                if ($SRate_3d->updateRateSub0toSub12($val))
                {
                    ++$okI;
                }
                ++$tempI;
            }
        }
        if ($okI == $tempI)
        {
            $fieldArr['betcontent'] = "【" . $RateConfig_3d->playtypeArr02[$playtype] . "】页面 前三,中三同步";
            $fieldArr['orate'] = "0";
            $fieldArr['nrate'] = "0";
            setRateRecord($fieldArr);
            $alertMsg = "alert('已将【" . $RateConfig_3d->playtypeArr02[$playtype] . "】页面，前三中三赔率同步完成，请切换至前三、中三页面检查');";
        }
        else
        {
            $fieldArr['betcontent'] = "【" . $RateConfig_3d->playtypeArr02[$playtype] . "】页面 前三,中三同步失败";
            $fieldArr['orate'] = "0";
            $fieldArr['nrate'] = "0";
            setRateRecord($fieldArr);
            $alertMsg = "alert('已将【" . $RateConfig_3d->playtypeArr02[$playtype] . "】页面，前三中三赔率同步失败');";
        }
    }
    else
    {
        foreach ($fieldsArr as $val)
        {
            if ($show5N && in_array($val, $g_n3n5Arr))
            {
                $subIdArr = array ($subid);
                $subIdArr = array (2, 1, 0);
            }
            else
            {
                $subIdArr = array (0);
            }
            if (isset($SRate_3d->betForNumTbl[$val]))
            {
                $betTypeNumber = array ();
                foreach ($SRate_3d->betForNumTbl[$val] as $sKey => $sVal)
                {
                    $betTypeNumber[] = intval(substr($sKey, 1));
                }
            }
            else
            {
                $betTypeNumber = $RateConfig_3d->getBetTypeNumber($val);
            }
            foreach ($subIdArr as $subIdArrKey => $subIdArrVal)
            {
                $ratedata = array ();
                $rateBaseArr = $SRate_3d->getRates("0", $diskIdx, $val, $subIdArrVal);
                foreach ($betTypeNumber as $key2 => $val2)
                {
                    $tempStr = "n_{$val}_{$subIdArrVal}_{$diskIdx}_{$val2}";
                    if (isset($_POST[$tempStr]))
                    {
                        $floatval = floatval($_POST[$tempStr]);
                        $floatval = 0 < $floatval ? $floatval : "0";
                        $key2Idx = "r" . str_pad($val2, 2, 0, STR_PAD_LEFT);
                        $ratedata[$key2Idx] = $floatval;
                        if ($floatval != $rateBaseArr[$key2Idx])
                        {
                            $tempId = $val . "_" . $subIdArrVal;
                            $fieldArr['betcontent'] = " [{$betname_3d[$tempId]}]" . $RateConfig_3d->getBetContent($val, $val2, true) . " :: " . $g_disk_name[$diskIdx];
                            $fieldArr['orate'] = $rateBaseArr[$key2Idx];
                            $fieldArr['nrate'] = $floatval;
                            setRateRecord($fieldArr);
                        }
                        ++$okI;
                    }
                    //else
                   // {
                    //    diemsg("更新{$tblName}失败", "玩法资料与内容不齐全，无法更新({$tempStr})", "op.php?op=admin&fp=srate_3d&disk={$disk}&playtype={$playtype}&gametype={$gametype}");
                   // }
                }
                if (count($ratedata))
                {
                    $SRate_3d->updateRate("0", $diskIdx, $val, $ratedata, $subIdArrVal);
                }
            }
        }
        if (0 < $okI)
        {
            $msg = $tblName . "&nbsp;::&nbsp;" . $RateConfig_3d->playtypeArr02[$playtype] . "页面&nbsp;::&nbsp;" . $g_disk_name[$diskIdx] . "&nbsp;::&nbsp;" . "异动成&#21151;  (" . date("Y-m-d H:i:s") . ")";
        }
        else
        {
            $msg = "";
        }
    }
}
$SRateTbl_3d->reloadUrl = "op.php?op=admin&fp=srate_3d&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}&subFlag={$subFlag}&subid={$subid}";
$SRateTbl_3d->subURL = "op.php?op=admin&fp=srate_3d&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}&subFlag=1";
foreach ($fieldsArr as $val)
{
    if ($show5N && in_array($val, $g_n3n5Arr))
    {
        $subIdArr = array (2, 1, 0);
    }
    else
    {
        $subIdArr = array (0);
    }
    foreach ($subIdArr as $subIdArrKey => $subIdArrVal)
    {
        $rate_data = $SRate_3d->getRates(0, $diskIdx, $val, $subIdArrVal);
        if ($rate_data === false)
        {
            $rateStr = $RateConfig_3d->getBaseBet($val, $disk);
            $SRate_3d->addRates($diskIdx, 0, $val, $rateStr, $subIdArrVal);
            if ($disk == "a")
            {
                $rateStr = $RateConfig_3d->getBaseBet($val, "b");
                $SRate_3d->addRates(2, 0, $val, $rateStr, $subIdArrVal);
                $rateStr = $RateConfig_3d->getBaseBet($val, "c");
                $SRate_3d->addRates(3, 0, $val, $rateStr, $subIdArrVal);
                $rateStr = $RateConfig_3d->getBaseBet($val, "d");
                $SRate_3d->addRates(4, 0, $val, $rateStr, $subIdArrVal);
            }
        }
    }
}
$jslink = "<script>";
$jslink .= "var _myGlobalBetStr = \"" . $playtype . "\";";
$jslink .= "var _myGlobal5NStr = \"" . $show5NStr . "\";";
$jslink .= "$(function(){ $().chgIptClr();   ";
if ($playtype == "r2p")
{
    $jslink .= "\r\n$(\"#btnR2pType input:button\").click(function(){\r\n  var bid = $(this).attr(\"id\").split(\"_\")[1];\r\n  location.replace(\"op.php?op=admin&fp=srate_3d&playtype=" . $playtype . "&gametype=" . $gametype . "&disk=" . $disk . "&bid=\" + bid);\r\n  });\r\n";
}
$jslink .= "});</script>";
$jslink .= "<script src=\"js_3d/showRateRecord.js\"></script>";
$jslink .= "<script src=\"js_3d/js3d.js\"></script>";
$jslink .= "<script src=\"js_3d/jsRate3d.js\"></script>";
$ui->set("jslink", $jslink);
$ui->header();
$disks = "<select onchange=\"location.replace('op.php?op=admin&fp=srate_3d&playtype=" . $playtype . $bidstr . "&gametype={$gametype}&disk='+this.value)\">";
$disks .= "<option value=a" . ( $disk == "a" ? " selected" : "" ) . ">A 盘</option>";
$disks .= "<option value=b" . ( $disk == "b" ? " selected" : "" ) . ">B 盘</option>";
$disks .= "<option value=c" . ( $disk == "c" ? " selected" : "" ) . ">C 盘</option>";
$disks .= "<option value=d" . ( $disk == "d" ? " selected" : "" ) . ">D 盘</option>";
$disks .= "</select>";
$gameTypeStr = getOptionList($gametype, "op.php?op=admin&fp=srate_3d&playtype=" . $playtype . $bidstr . "&disk={$disk}");
$synRateFlag = 0;
if ($chkGametype == 1)
{
    $gameTypeStr = $gameTypeStr . "<input type='submit' value='福体彩同步' id='rateSynGametype' class=\"nobtnclass colorBtnGray\" />";
    $synRateFlag = 1;
    $synStr = "【{$tblName}】 赔率为主, 福体彩赔率同步";
}
else if ($show5N)
{
    $gameTypeStr = $gameTypeStr . "<input type='submit' value='五码同步' id='rateSynGametype' alt='不含上海' class=\"nobtnclass colorBtnGray\" />";
    $synRateFlag = 1;
    $synStr = "【{$tblName}】 赔率为主, 同步其他五码彩类赔率";
}
else if (!$g_5number_3d && 2 < $gametype)
{
    $gameTypeStr = $gameTypeStr . "<input type='submit' value='时时彩同步' id='rateSynGametype' alt='所有三码时时彩都同步'  class=\"nobtnclass colorBtnGray\" />";
    $synRateFlag = 1;
    $synStr = "【{$tblName}】 赔率为主, 同步其他三码时时彩赔率";
}
include( "admin_menu_3d.php" );
$playtypeArr = $RateConfig_3d->playtypeArr02;
$playMenu = "";
$playMenuArr = array ();
foreach ($playtypeArr as $key => $val)
{
    if ($key == $playtype)
    {
        $playMenuArr[] = "<span class=\"cBig\">{$val}</span>";
    }
    else
    {
        $playMenuArr[] = "<a href=\"op.php?op=admin&fp=srate_3d&gametype={$gametype}&playtype={$key}\">{$val}</a>";
    }
}
$playMenu = implode("&nbsp;|&nbsp;", $playMenuArr);
$playMenu2 = "<input type=\"button\" value=\"赔率异动纪录\" class=\"nobtnclass colorBtnGray\" onclick=\"javascript:showRateRecordPageBase({$gametype},'2');\"  />";
$g_5number_3dStrTitle="";
if ($subFlag && $show5N)
{
    echo "<script>";
    echo $alertMsg;
    echo "$(function(){\r\n    $(\"input#synSub0toSub12\").click(function(){\r\n      if(!confirm(\"确定要将 【" . $g_gametype_3d[$gametype]['ch'] . "】 " . $RateConfig_3d->playtypeArr02[$playtype] . " 页面中的玩法[前三],[中三]同步[後三]赔率(包含所有盘类)?\")){\r\n        return false;  \r\n      }\r\n    });\r\n  });\r\n  </script>\r\n  ";
}
if ($synRateFlag)
{
    $acURL = "op.php?op=admin&fp=srate_3d&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}";
    echo "<script>";
    echo $alertMsgSyn;
    echo "$(function(){\r\n    $(\"input#rateSynGametype\").click(function(){\r\n      if(confirm(\"确定要以 " . $synStr . "(包含所有盘类)?\")){\r\n        $.post(\"" . $acURL . "\", {rateSynGametype:\"1\"},function() {\r\n          alert(\"同步完成!请切换至其他彩类复查是否同步\");\r\n        });\r\n      }\r\n      return true;\r\n    });\r\n  });\r\n  </script>\r\n  ";
}
echo "<div id=\"divRateRecord\"></div>";
echo "<style> thead, th{font-size:0.9em;} </style>";
echo "<div class='title0 bgImg_{$gametype}' style='width:753px;padding:5px;'><span style='float:left'>{$tblName}&nbsp;&nbsp;&nbsp;{$playtypeArr[$playtype]} &nbsp;&nbsp;&nbsp;{$g_5number_3dStrTitle}基本赔率设定 ---  {$disks}</span><span style='float:right'>{$gameTypeStr} {$playMenu2}</span><br /><br />{$playMenu}</div>";
echo $msg == "" ? "" : "<div class='msgBox-yellow'>{$msg}</div>";
echo "<form action='op.php?op=admin&fp=srate_3d&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}' method='post'>";
echo $SRateTbl_3d->show_srateTbl($playtype, $diskIdx, $subid, $bid);
echo "</form>";
echo "<span> ※ 快调时, <font style='background-color:#FF9291'>浅红底</font>表示赔率小於 1 </span>";
echo "<br /><span> ※ {$tblName}玩法，可设定赔率至小数点下第三位。</span>";
echo "<br /><span> ※ [<input type='button' class='colorBtnGray' value='- ' /><input type='button' class='colorBtnGray' value='+' />]按钮 每次异动量为<font style='background-color:#FF9291'>0.01</font>，异动後请记得按[确定更改]钮</span>";
echo "<br /><span> ※ 赔率快速归零小技巧:增量栏位输入负极大值(例 -999999)，按「全部」钮即可。</span>";
echo "</td></tr></table>";
$ui->footer();